﻿using B.S.DataBase.MyProject.API.Appicant.Command;
using B.S.DataBase.MyProject.API.DTOs;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyRead.API.Appicant.Command.Approval;
using B.S.DataBase.MyRead.API.Appicant.Command.Menus;
using B.S.DataBase.MyRead.API.Appicant.Command.RoleCommand;
using B.S.DataBase.MyRead.API.Appicant.Command.Routing;
using B.S.DataBase.MyRead.API.DTOs;
using B.S.DataBase.MyWrite.API.Appicant.Command.Roles;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.DataBase.MyProject.API.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MessageController : ControllerBase
    {
        private readonly IMediator mediator;

        public MessageController(IMediator mediator)
        {
            this.mediator = mediator;
        }


        #region 登录 用户列表
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<User>> Login([FromQuery] LoginCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 查询用户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<UserDTOs>>> GetUser([FromQuery] GetUserCommand request)
        {
            return await mediator.Send(request);
        }


        /// <summary>
        /// 用户名称唯一
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<object>> OneUserName([FromQuery] OnenessUserNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 反填用户单表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<APIResult<User>> FanTianUser([FromQuery] GetFanTianUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 部门id查询名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpGet]
        public Task<APIResult<List<User>>> GetDepUserName([FromQuery] DepUserNameCommand request)
        {
            return mediator.Send(request);
        }
        #endregion

        #region 角色管理
        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        [HttpGet]
        public Task<APIResult<List<Role>>> GetRole([FromQuery] GetRoleCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色名称唯一验证
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<object>> OneRoleName([FromQuery] OnenessRoleNameCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 角色反填(id查询)
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<Role>> RoleFanTian([FromQuery] RoleFanTianCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 根据部门Id查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<User>>> GetUserName([FromQuery] GetDepIdUserCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 通过角色ID查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<UserNameDTOs>>> GetUserNameRoleId([FromQuery] GetUserNameRoleidCommand request)
        {
            return mediator.Send(request);
        }
        #endregion


        #region 菜单
        /// <summary>
        /// 菜单列表(不包含父Id为0)
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<MenuDTO>>> GetMenu([FromQuery] GetMenuCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 菜单列表(全部)
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<List<Menu>>> GetMenuAll([FromQuery] GetMenuAllCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 菜单名称唯一性验证
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<object>> Only([FromQuery] OnlyMenuNameCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 菜单名获取父级ID
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回任务</returns>
        [HttpGet]
        public Task<APIResult<object>> GetPId([FromQuery] QueryPIdCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查询菜单名称
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Menu>>> RoleMenu([FromQuery]GetRoleMenuCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 通过角色编号反填出菜单表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<RoleMenu>>> GetRoleMenu([FromQuery] GetRoleMenuTreeCommand request)
        {
            return await mediator.Send(request);
        }

        #endregion

        #region 路由
        /// <summary>
        /// 路由跳转
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<MenuRouterDTO>>> GetRouter([FromQuery]GetRouterCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 审批
        /// <summary>
        /// 查询部门领导
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<User>>> GetDepartMentHead([FromQuery]GetDepartMentHeadCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 请假申请部门
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<APIPaging<LeaveApplication>>> QueryApproval([FromQuery]QueryApprovalCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 反填请假
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<object>> BackfillingApproval([FromQuery]BackfillingApprovalCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 查询同级领导
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<object>> PeerlevelApprovalJudgment(PeerlevelApprovalJudgmentCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion
        [HttpGet]
        public async Task<APIResult<string>> Getdep([FromQuery]GetDepLeaderCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        }
}
